package com.fourfinance.validation;

import java.util.Date;

import com.fourfinance.model.domain.Ip;
import com.fourfinance.util.LenderConstants;
import com.fourfinance.util.LenderUtil;

public class LenderAppValidator {

	/**
	 * Validates maximum amount (Risk Analyze) 
	 * 
	 * @param amount
	 * @return false if not allowed
	 */
	public static Boolean isAmountAllowed(Long amount){	
		if(amount > LenderConstants.MAX_AMOUNT){
			return false;
		} else {
			return true;
		}
	}
	
	/**
	 * Validates application time (Risk Analyze)
	 * 
	 * @param currentDate
	 * @return false if not allowed
	 */
	public static Boolean isTimingAllowed(Date currentDate){
		Date minDate = LenderUtil.getMinTime();		
		Date maxDate = LenderUtil.getMaxTime();		
		if(currentDate.after(minDate) || currentDate.before(maxDate)){
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Validates maximum attempt number from single IP address (Risk Analyze)
	 * @param ip
	 * @return false if not allowed
	 */
	public static Boolean isAttemptAllowed(Ip ip){
		if(ip.getAttemptCount() <= LenderConstants.MAX_ATTEMPT && LenderUtil.isToday(ip.getLastAttempt())){
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Validates term date
	 * 
	 * @param term
	 * @return
	 */
	public static Boolean isTermInFuture(Date term){
		if(term.after(new Date())){
			return true;
		} else {
			return false;
		}
	}
	
}
